package wangjg.android.media.record;

import java.io.IOException;

import android.media.AudioManager;
import android.media.MediaPlayer;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;

public class MyMediaPlayer implements Callback {
	private SurfaceHolder holder;
	private MediaPlayer mediaPlayer = new MediaPlayer();
	
	public void start(){
		try {
			String url = "/mnt/sdcard/test_nb.amr"; // your URL here
			if(holder!=null)
				mediaPlayer.setDisplay(holder);
			mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
			mediaPlayer.setDataSource(url);
			mediaPlayer.prepare(); // might take long! (for buffering, etc)
			mediaPlayer.start();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void stop(){
		mediaPlayer.stop();
	}

	@Override
	public void surfaceChanged(SurfaceHolder holder, int format, int width,
			int height) {
		this.holder = holder;
	}

	@Override
	public void surfaceCreated(SurfaceHolder holder) {
		this.holder = holder;
	}

	@Override
	public void surfaceDestroyed(SurfaceHolder holder) {
		this.holder = null;
	}
}
